<?php 

/* Crontab command examples:-
@reboot        Run once, at startup.
@yearly        Run once a year, "0 0 1 1 *".
@annually      (same as @yearly)
@monthly       Run once a month, "0 0 1 * *".
@weekly        Run once a week, "0 0 * * 0".
@daily         Run once a day, "0 0 * * *".
@midnight      (same as @daily)
@hourly        Run once an hour, "0 * * * *".
*/


require_once 'config.php';

if (isset($_POST['schedule_post']))
{
	$dbConn = mysql_pconnect (DBHOST,DBUSER,DBPASS) or die ('MySQL connect failed. ' . mysql_error());
	mysql_select_db(DBNAME);
	echo $_POST['post_type'];
	echo $_POST['time'];
	$trigger = '/home/rsoni/public_html/trigger.php&type=';
	
	
	switch ($_POST['time']) {
	    case minute:
	        $cron_time = "*/1 * * * * ";
	        break;
		case hour:
			$cron_time = "0 * * * * ";
			break;
		case day:
			$cron_time = "0 0 * * * ";
			break;
			
		case month:
			$cron_time = "0 0 1 * * ";
			break;
		
		case week:
			$cron_time = "0 0 * * 0 ";	
			break;
	}
	
	$trigger.=$_POST['post_type'];
	
	mysql_query("INSERT INTO `schedules` VALUES (NULL,'$cron_time','$trigger','trigger');") or die(mysql_error());

}	
?>

<html>
<body>

	<form method="POST"  action="insert_trigger.php">
		Select a Post Type: <select name="post_type" >
							<option value="forum"> Forum </option>
							<option value="file"> File </option>
							<option value="issue"> Issue Tracking</option>
							<option value="svn"> SVN</option>
							<option value="wiki"> Wiki</option>
							<option value="all"> All</option>
							</select>
							
		Get report every: <select name="time" >
							<option value="minute">  Minute </option>
							<option value="hour">  Hour </option>
							<option value="day">  Day </option>
							<option value="week">  Week </option
							<option value="month">  Month </option>
							</select>
							
							<input type=hidden name="schedule_post"> 
	<input type="submit" value="Schedule">
	</form>

</body>
</html>

